$(document).ready(function() {
	
	$('#filterDate').datepicker({
		maxDate: "+0D",
		dateFormat: 'yy-mm-dd'
	});
	
});


function searchSales(){
	var dateFilter = $("#filterDate").val();
	$("#loading-message").text("Searching sales on "+ dateFilter  +" . Please wait.");
	$("#loading-box").dialog("open");
	
	var url = getUrl('reports', 'getSales');
	
	var request = {
			dateFilter: dateFilter
	}
	
	if(dateFilter != ""){
		$.post(url, request , function(result) {
			
			$("#loading-box").dialog("close");
			
			$("#resultDiv").html(result);
			
		}).fail(function() {alert("something went wrong!");$("#loading-box").dialog("close"); });
	} 
}

function searchComplaints(){
	var dateFilter = $("#filterDate").val();
	$("#loading-message").text("Searching complaints on "+ dateFilter  +" . Please wait.");
	$("#loading-box").dialog("open");
	
	var url = getUrl('reports', 'getComplaint');
	
	var request = {
			dateFilter: dateFilter
	}
	
	if(dateFilter != ""){
		$.post(url, request , function(result) {
			
			$("#loading-box").dialog("close");
			
			$("#resultDiv").html(result);
			
		}).fail(function() {alert("something went wrong!");$("#loading-box").dialog("close"); });
	} 
}

function exportSalesToExcel(){
	
	var url = getUrl('export', 'exportSales');
	
	var data='<table>'+$("#salesReportResult").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
	$('body').prepend("<form method='post' action='"+url+"' style='display:none' id='ReportTableData'><input type='text' name='tableData' value='"+data+"' ></form>");
	 $('#ReportTableData').submit().remove();
	 return false;
}

function exportComplaintsToExcel(){
	
	var url = getUrl('export', 'exportComplaints');
	
	var data='<table>'+$("#salesReportResult").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
	$('body').prepend("<form method='post' action='"+url+"' style='display:none' id='ReportTableData'><input type='text' name='tableData' value='"+data+"' ></form>");
	 $('#ReportTableData').submit().remove();
	 return false;
}

function exportInventoryToExcel(){
	
	var url = getUrl('export', 'exportInventory');
	
	var data='<table>'+$("#inventoryReportResult").html().replace(/<a\/?[^>]+>/gi, '')+'</table>';
	$('body').prepend("<form method='post' action='"+url+"' style='display:none' id='ReportTableData'><input type='text' name='tableData' value='"+data+"' ></form>");
	 $('#ReportTableData').submit().remove();
	 return false;
}


	
